using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace OsdmSoftware.CommonLibrary
{
    public class FileDialogPicturePreview: PictureBox, IPreviewControl
    {
        CompleteFileDialog dialog;
        public FileDialogPicturePreview()
        {
            this.SizeMode = PictureBoxSizeMode.StretchImage;
        }

        public void DockToDialog(Panel panel, CompleteFileDialog dialog)
        {
            this.dialog = dialog;
            panel.Controls.Add(this);
            this.Dock = DockStyle.Fill;
        }

        public void SelectedFileChanged()
        {
            Image im = this.Image;
            this.Image = null;
            if (im != null)
                im.Dispose();
            if (!String.IsNullOrEmpty(dialog.FileName))
                this.Image = new Bitmap(dialog.FileName);
            else
                this.Image = null;
        }

        public void UndockFromDialog()
        {
            Parent.Controls.Remove(this);
            dialog = null;
        }
    }
}